﻿namespace WizardEngine.Core
{
    using System;
    using System.Collections.Generic;
    using System.Runtime.Serialization;
    using System.Diagnostics.Contracts;

    /// <summary>
    /// Base class for all custom flow state implementations. 
    /// Gathers necessary functionalities to handle flow execution and persistence correctly.
    /// </summary>
    [Serializable]
    public abstract class FlowState : ICloneable
    {
        private readonly Stack<VisitedStep> previousSteps = new Stack<VisitedStep>();
        public Step CurrentStep { get; protected set; }

        public void Visit(Step step, FlowState state)
        {
            Contract.Assert(step != null);
            Contract.Assert(state != null);

            var visitedStep = new VisitedStep(step, state);
            this.CurrentStep = step;
            previousSteps.Push(visitedStep);
        }

        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        /// <filterpriority>2</filterpriority>
        public abstract object Clone();
    }
}
